package com.lz.timer.an;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import lombok.extern.slf4j.Slf4j;

/**
 * 应用启动入口类
 *
 * @author rench
 */
@Slf4j
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableEurekaClient
public class Main {

    public static void main(String[] args) throws Exception {
        log.info("=====开始启动=====");
        Init.init();
        SpringApplication.run(Main.class, args);

        Thread shutdownHook = new Thread(() -> {
            log.debug("===========shutdownHook...============");
            try {
                Init.destroy();
            } catch (Exception e) {
                e.printStackTrace();
                log.error("Exception={}", ExceptionUtils.getFullStackTrace(e));
            }
        });

        Runtime.getRuntime().addShutdownHook(shutdownHook);
        log.info("=====启动完成=====");
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
